{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Task\n",
    "\n",
    "In section 2, Table 4, we compare health outcomes across countries. This comparison is done with SHARE and HRS data along with data on remaining life expectancy from mortality.org, the Human Mortality Database. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 310,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd \n",
    "import numpy as np "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Health Data\n",
    "\n",
    "We use data from our sample of age 50 to 75 respondents in SHARE and HRS 2004. We compute the prevalence of various health conditions in the data (weighted). "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 311,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_pickle('../data_sources/hrs-share_wide_select.pkl')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 312,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>riwstat_w1</th>\n",
       "      <th>riwstat_w2</th>\n",
       "      <th>rage_w1</th>\n",
       "      <th>rage_w2</th>\n",
       "      <th>radla_w1</th>\n",
       "      <th>radla_w2</th>\n",
       "      <th>wgid_w1</th>\n",
       "      <th>wgid_w2</th>\n",
       "      <th>hitot_w1</th>\n",
       "      <th>hitot_w2</th>\n",
       "      <th>...</th>\n",
       "      <th>hhidpn_w2</th>\n",
       "      <th>pppx_w2</th>\n",
       "      <th>rdrinkv_w2</th>\n",
       "      <th>cid</th>\n",
       "      <th>cname</th>\n",
       "      <th>share</th>\n",
       "      <th>gg2</th>\n",
       "      <th>gb2</th>\n",
       "      <th>g_w1</th>\n",
       "      <th>g_w2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>000003010</th>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>68.0</td>\n",
       "      <td>70.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4067.0</td>\n",
       "      <td>4093.0</td>\n",
       "      <td>43736.506385</td>\n",
       "      <td>34076.999401</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>8</td>\n",
       "      <td>US</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>000003020</th>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>65.0</td>\n",
       "      <td>67.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4132.0</td>\n",
       "      <td>4210.0</td>\n",
       "      <td>43736.506385</td>\n",
       "      <td>34076.999401</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>8</td>\n",
       "      <td>US</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>010001010</th>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>64.0</td>\n",
       "      <td>66.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>6890.0</td>\n",
       "      <td>7434.0</td>\n",
       "      <td>9298.986526</td>\n",
       "      <td>9329.509552</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>8</td>\n",
       "      <td>US</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>010004010</th>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>64.0</td>\n",
       "      <td>66.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5011.0</td>\n",
       "      <td>5217.0</td>\n",
       "      <td>75047.850487</td>\n",
       "      <td>63443.065392</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>8</td>\n",
       "      <td>US</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>010004040</th>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>58.0</td>\n",
       "      <td>60.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5182.0</td>\n",
       "      <td>5299.0</td>\n",
       "      <td>75047.850487</td>\n",
       "      <td>63443.065392</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>8</td>\n",
       "      <td>US</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 52 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           riwstat_w1  riwstat_w2  rage_w1  rage_w2  radla_w1  radla_w2  \\\n",
       "000003010         1.0         1.0     68.0     70.0       0.0       0.0   \n",
       "000003020         1.0         1.0     65.0     67.0       0.0       0.0   \n",
       "010001010         1.0         1.0     64.0     66.0       0.0       0.0   \n",
       "010004010         1.0         1.0     64.0     66.0       1.0       0.0   \n",
       "010004040         1.0         1.0     58.0     60.0       0.0       0.0   \n",
       "\n",
       "           wgid_w1  wgid_w2      hitot_w1      hitot_w2  ...  hhidpn_w2  \\\n",
       "000003010   4067.0   4093.0  43736.506385  34076.999401  ...        NaN   \n",
       "000003020   4132.0   4210.0  43736.506385  34076.999401  ...        NaN   \n",
       "010001010   6890.0   7434.0   9298.986526   9329.509552  ...        NaN   \n",
       "010004010   5011.0   5217.0  75047.850487  63443.065392  ...        NaN   \n",
       "010004040   5182.0   5299.0  75047.850487  63443.065392  ...        NaN   \n",
       "\n",
       "           pppx_w2  rdrinkv_w2  cid  cname  share  gg2  gb2  g_w1  g_w2  \n",
       "000003010      NaN         NaN    8     US      0  1.0  NaN   1.0   1.0  \n",
       "000003020      NaN         NaN    8     US      0  1.0  NaN   1.0   1.0  \n",
       "010001010      NaN         NaN    8     US      0  1.0  NaN   1.0   1.0  \n",
       "010004010      NaN         NaN    8     US      0  NaN  1.0   0.0   1.0  \n",
       "010004040      NaN         NaN    8     US      0  1.0  NaN   1.0   1.0  \n",
       "\n",
       "[5 rows x 52 columns]"
      ]
     },
     "execution_count": 312,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 313,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['tot_cond'] = df[['rhibpe_w1','rdiabe_w1','rlunge_w1','rhearte_w1','rstroke_w1']].sum(axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We tag along remaining life expectancy data to these (from HMD, 2005, both sexes). We input it here just to get the weighted average in Europe right. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 314,
   "metadata": {},
   "outputs": [],
   "source": [
    "ex = {1: 31.14,2: 32.11,3: 31.22,4:32.26,5:32.66,6:32.56,7:30.15,8:30.65}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 315,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['ex50'] = df['cid'].replace(ex)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 316,
   "metadata": {},
   "outputs": [],
   "source": [
    "outcomes = ['rhibpe_w1','rdiabe_w1','rlunge_w1','rhearte_w1','rstroke_w1','tot_cond','radla_w1','ex50']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 317,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>rhibpe_w1</th>\n",
       "      <th>rdiabe_w1</th>\n",
       "      <th>rlunge_w1</th>\n",
       "      <th>rhearte_w1</th>\n",
       "      <th>rstroke_w1</th>\n",
       "      <th>tot_cond</th>\n",
       "      <th>radla_w1</th>\n",
       "      <th>ex50</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>28490.000000</td>\n",
       "      <td>28489.000000</td>\n",
       "      <td>28494.000000</td>\n",
       "      <td>28487.000000</td>\n",
       "      <td>28497.000000</td>\n",
       "      <td>28594.000000</td>\n",
       "      <td>28591.000000</td>\n",
       "      <td>28594.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>0.387820</td>\n",
       "      <td>0.129453</td>\n",
       "      <td>0.060188</td>\n",
       "      <td>0.134658</td>\n",
       "      <td>0.040215</td>\n",
       "      <td>0.749598</td>\n",
       "      <td>0.090098</td>\n",
       "      <td>31.265974</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>0.489633</td>\n",
       "      <td>0.339140</td>\n",
       "      <td>0.242660</td>\n",
       "      <td>0.344741</td>\n",
       "      <td>0.202275</td>\n",
       "      <td>0.932723</td>\n",
       "      <td>0.286328</td>\n",
       "      <td>0.808048</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>-2.000000</td>\n",
       "      <td>-2.000000</td>\n",
       "      <td>-2.000000</td>\n",
       "      <td>-2.000000</td>\n",
       "      <td>-2.000000</td>\n",
       "      <td>-10.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>30.150000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>30.650000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>30.650000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>32.110000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>32.660000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          rhibpe_w1     rdiabe_w1     rlunge_w1    rhearte_w1    rstroke_w1  \\\n",
       "count  28490.000000  28489.000000  28494.000000  28487.000000  28497.000000   \n",
       "mean       0.387820      0.129453      0.060188      0.134658      0.040215   \n",
       "std        0.489633      0.339140      0.242660      0.344741      0.202275   \n",
       "min       -2.000000     -2.000000     -2.000000     -2.000000     -2.000000   \n",
       "25%        0.000000      0.000000      0.000000      0.000000      0.000000   \n",
       "50%        0.000000      0.000000      0.000000      0.000000      0.000000   \n",
       "75%        1.000000      0.000000      0.000000      0.000000      0.000000   \n",
       "max        1.000000      1.000000      1.000000      1.000000      1.000000   \n",
       "\n",
       "           tot_cond      radla_w1          ex50  \n",
       "count  28594.000000  28591.000000  28594.000000  \n",
       "mean       0.749598      0.090098     31.265974  \n",
       "std        0.932723      0.286328      0.808048  \n",
       "min      -10.000000      0.000000     30.150000  \n",
       "25%        0.000000      0.000000     30.650000  \n",
       "50%        1.000000      0.000000     30.650000  \n",
       "75%        1.000000      0.000000     32.110000  \n",
       "max        5.000000      1.000000     32.660000  "
      ]
     },
     "execution_count": 317,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[outcomes].describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 318,
   "metadata": {},
   "outputs": [],
   "source": [
    "table = pd.DataFrame(index=np.arange(1,9),columns=outcomes)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Weighted prevalences"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 319,
   "metadata": {},
   "outputs": [],
   "source": [
    "for v in table.columns:\n",
    "    for c in table.index: \n",
    "        table.loc[c,v] = (df.loc[df.cid==c,v] * df.loc[df.cid==c,'wgid_w1']).sum()/df.loc[df.cid==c,'wgid_w1'].sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 320,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>rhibpe_w1</th>\n",
       "      <th>rdiabe_w1</th>\n",
       "      <th>rlunge_w1</th>\n",
       "      <th>rhearte_w1</th>\n",
       "      <th>rstroke_w1</th>\n",
       "      <th>tot_cond</th>\n",
       "      <th>radla_w1</th>\n",
       "      <th>ex50</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.338332</td>\n",
       "      <td>0.105475</td>\n",
       "      <td>0.042372</td>\n",
       "      <td>0.090277</td>\n",
       "      <td>0.033663</td>\n",
       "      <td>0.610119</td>\n",
       "      <td>0.06687</td>\n",
       "      <td>31.14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.260704</td>\n",
       "      <td>0.079245</td>\n",
       "      <td>0.025064</td>\n",
       "      <td>0.109462</td>\n",
       "      <td>0.02762</td>\n",
       "      <td>0.502094</td>\n",
       "      <td>0.054418</td>\n",
       "      <td>32.11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.238739</td>\n",
       "      <td>0.074387</td>\n",
       "      <td>0.061635</td>\n",
       "      <td>0.090995</td>\n",
       "      <td>0.034944</td>\n",
       "      <td>0.5007</td>\n",
       "      <td>0.051532</td>\n",
       "      <td>31.22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.288678</td>\n",
       "      <td>0.124678</td>\n",
       "      <td>0.044849</td>\n",
       "      <td>0.077439</td>\n",
       "      <td>0.018381</td>\n",
       "      <td>0.554025</td>\n",
       "      <td>0.069142</td>\n",
       "      <td>32.26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.349513</td>\n",
       "      <td>0.106708</td>\n",
       "      <td>0.059763</td>\n",
       "      <td>0.082135</td>\n",
       "      <td>0.020997</td>\n",
       "      <td>0.619116</td>\n",
       "      <td>0.075021</td>\n",
       "      <td>32.66</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>0.256112</td>\n",
       "      <td>0.086369</td>\n",
       "      <td>0.047844</td>\n",
       "      <td>0.102731</td>\n",
       "      <td>0.022951</td>\n",
       "      <td>0.516008</td>\n",
       "      <td>0.072206</td>\n",
       "      <td>32.56</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>0.277222</td>\n",
       "      <td>0.066038</td>\n",
       "      <td>0.059248</td>\n",
       "      <td>0.063447</td>\n",
       "      <td>0.037674</td>\n",
       "      <td>0.503629</td>\n",
       "      <td>0.069422</td>\n",
       "      <td>30.15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>0.445441</td>\n",
       "      <td>0.147332</td>\n",
       "      <td>0.068621</td>\n",
       "      <td>0.159019</td>\n",
       "      <td>0.044803</td>\n",
       "      <td>0.865216</td>\n",
       "      <td>0.108223</td>\n",
       "      <td>30.65</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  rhibpe_w1 rdiabe_w1 rlunge_w1 rhearte_w1 rstroke_w1  tot_cond  radla_w1  \\\n",
       "1  0.338332  0.105475  0.042372   0.090277   0.033663  0.610119   0.06687   \n",
       "2  0.260704  0.079245  0.025064   0.109462    0.02762  0.502094  0.054418   \n",
       "3  0.238739  0.074387  0.061635   0.090995   0.034944    0.5007  0.051532   \n",
       "4  0.288678  0.124678  0.044849   0.077439   0.018381  0.554025  0.069142   \n",
       "5  0.349513  0.106708  0.059763   0.082135   0.020997  0.619116  0.075021   \n",
       "6  0.256112  0.086369  0.047844   0.102731   0.022951  0.516008  0.072206   \n",
       "7  0.277222  0.066038  0.059248   0.063447   0.037674  0.503629  0.069422   \n",
       "8  0.445441  0.147332  0.068621   0.159019   0.044803  0.865216  0.108223   \n",
       "\n",
       "    ex50  \n",
       "1  31.14  \n",
       "2  32.11  \n",
       "3  31.22  \n",
       "4  32.26  \n",
       "5  32.66  \n",
       "6  32.56  \n",
       "7  30.15  \n",
       "8  30.65  "
      ]
     },
     "execution_count": 320,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "table"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Table with European average"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 321,
   "metadata": {},
   "outputs": [],
   "source": [
    "table_sum = pd.DataFrame(index=[9,10],columns=outcomes)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 322,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['europe'] = np.where(df['cid']!=8,9,10)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 323,
   "metadata": {},
   "outputs": [],
   "source": [
    "for v in table_sum.columns:\n",
    "    for c in table_sum.index: \n",
    "        d = df.loc[(df.europe==c) & (~df[v].isna()),:]\n",
    "        table_sum.loc[c,v] = (d[v] * d['wgid_w1']).sum()/d['wgid_w1'].sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 324,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>rhibpe_w1</th>\n",
       "      <th>rdiabe_w1</th>\n",
       "      <th>rlunge_w1</th>\n",
       "      <th>rhearte_w1</th>\n",
       "      <th>rstroke_w1</th>\n",
       "      <th>tot_cond</th>\n",
       "      <th>radla_w1</th>\n",
       "      <th>ex50</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>0.309545</td>\n",
       "      <td>0.101905</td>\n",
       "      <td>0.048994</td>\n",
       "      <td>0.090082</td>\n",
       "      <td>0.026521</td>\n",
       "      <td>0.572638</td>\n",
       "      <td>0.068951</td>\n",
       "      <td>31.959003</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>0.445854</td>\n",
       "      <td>0.147463</td>\n",
       "      <td>0.068666</td>\n",
       "      <td>0.159199</td>\n",
       "      <td>0.044831</td>\n",
       "      <td>0.865216</td>\n",
       "      <td>0.108248</td>\n",
       "      <td>30.65</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   rhibpe_w1 rdiabe_w1 rlunge_w1 rhearte_w1 rstroke_w1  tot_cond  radla_w1  \\\n",
       "9   0.309545  0.101905  0.048994   0.090082   0.026521  0.572638  0.068951   \n",
       "10  0.445854  0.147463  0.068666   0.159199   0.044831  0.865216  0.108248   \n",
       "\n",
       "         ex50  \n",
       "9   31.959003  \n",
       "10      30.65  "
      ]
     },
     "execution_count": 324,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "table_sum"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Collecting and cleaning up"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 325,
   "metadata": {},
   "outputs": [],
   "source": [
    "table = table.append(table_sum.loc[9,:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 326,
   "metadata": {},
   "outputs": [],
   "source": [
    "map_cid = {1: 'Germany',2: 'Sweden',3: 'Netherlands',4:'Spain',5:'Italy',6:'France',7:'Denmark',8:'United States',9:'Europe'}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 327,
   "metadata": {},
   "outputs": [],
   "source": [
    "table.index = table.index.to_series().replace(map_cid)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 328,
   "metadata": {},
   "outputs": [],
   "source": [
    "table.columns = ['hypertension','diabetes','lung','heart','stroke','total cond.','ADLs','Life exp (50)']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 329,
   "metadata": {},
   "outputs": [],
   "source": [
    "for c in table.columns:\n",
    "    table[c] = table[c].astype('float64')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 330,
   "metadata": {},
   "outputs": [],
   "source": [
    "table = table.loc[['Germany','Sweden','Netherlands','Spain','Italy','France','Denmark','Europe','United States'],:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 331,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>hypertension</th>\n",
       "      <th>diabetes</th>\n",
       "      <th>lung</th>\n",
       "      <th>heart</th>\n",
       "      <th>stroke</th>\n",
       "      <th>total cond.</th>\n",
       "      <th>ADLs</th>\n",
       "      <th>Life exp (50)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Germany</th>\n",
       "      <td>0.338</td>\n",
       "      <td>0.105</td>\n",
       "      <td>0.042</td>\n",
       "      <td>0.090</td>\n",
       "      <td>0.034</td>\n",
       "      <td>0.610</td>\n",
       "      <td>0.067</td>\n",
       "      <td>31.140</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sweden</th>\n",
       "      <td>0.261</td>\n",
       "      <td>0.079</td>\n",
       "      <td>0.025</td>\n",
       "      <td>0.109</td>\n",
       "      <td>0.028</td>\n",
       "      <td>0.502</td>\n",
       "      <td>0.054</td>\n",
       "      <td>32.110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Netherlands</th>\n",
       "      <td>0.239</td>\n",
       "      <td>0.074</td>\n",
       "      <td>0.062</td>\n",
       "      <td>0.091</td>\n",
       "      <td>0.035</td>\n",
       "      <td>0.501</td>\n",
       "      <td>0.052</td>\n",
       "      <td>31.220</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Spain</th>\n",
       "      <td>0.289</td>\n",
       "      <td>0.125</td>\n",
       "      <td>0.045</td>\n",
       "      <td>0.077</td>\n",
       "      <td>0.018</td>\n",
       "      <td>0.554</td>\n",
       "      <td>0.069</td>\n",
       "      <td>32.260</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Italy</th>\n",
       "      <td>0.350</td>\n",
       "      <td>0.107</td>\n",
       "      <td>0.060</td>\n",
       "      <td>0.082</td>\n",
       "      <td>0.021</td>\n",
       "      <td>0.619</td>\n",
       "      <td>0.075</td>\n",
       "      <td>32.660</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>France</th>\n",
       "      <td>0.256</td>\n",
       "      <td>0.086</td>\n",
       "      <td>0.048</td>\n",
       "      <td>0.103</td>\n",
       "      <td>0.023</td>\n",
       "      <td>0.516</td>\n",
       "      <td>0.072</td>\n",
       "      <td>32.560</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Denmark</th>\n",
       "      <td>0.277</td>\n",
       "      <td>0.066</td>\n",
       "      <td>0.059</td>\n",
       "      <td>0.063</td>\n",
       "      <td>0.038</td>\n",
       "      <td>0.504</td>\n",
       "      <td>0.069</td>\n",
       "      <td>30.150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Europe</th>\n",
       "      <td>0.310</td>\n",
       "      <td>0.102</td>\n",
       "      <td>0.049</td>\n",
       "      <td>0.090</td>\n",
       "      <td>0.027</td>\n",
       "      <td>0.573</td>\n",
       "      <td>0.069</td>\n",
       "      <td>31.959</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>United States</th>\n",
       "      <td>0.445</td>\n",
       "      <td>0.147</td>\n",
       "      <td>0.069</td>\n",
       "      <td>0.159</td>\n",
       "      <td>0.045</td>\n",
       "      <td>0.865</td>\n",
       "      <td>0.108</td>\n",
       "      <td>30.650</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               hypertension  diabetes   lung  heart  stroke  total cond.  \\\n",
       "Germany               0.338     0.105  0.042  0.090   0.034        0.610   \n",
       "Sweden                0.261     0.079  0.025  0.109   0.028        0.502   \n",
       "Netherlands           0.239     0.074  0.062  0.091   0.035        0.501   \n",
       "Spain                 0.289     0.125  0.045  0.077   0.018        0.554   \n",
       "Italy                 0.350     0.107  0.060  0.082   0.021        0.619   \n",
       "France                0.256     0.086  0.048  0.103   0.023        0.516   \n",
       "Denmark               0.277     0.066  0.059  0.063   0.038        0.504   \n",
       "Europe                0.310     0.102  0.049  0.090   0.027        0.573   \n",
       "United States         0.445     0.147  0.069  0.159   0.045        0.865   \n",
       "\n",
       "                ADLs  Life exp (50)  \n",
       "Germany        0.067         31.140  \n",
       "Sweden         0.054         32.110  \n",
       "Netherlands    0.052         31.220  \n",
       "Spain          0.069         32.260  \n",
       "Italy          0.075         32.660  \n",
       "France         0.072         32.560  \n",
       "Denmark        0.069         30.150  \n",
       "Europe         0.069         31.959  \n",
       "United States  0.108         30.650  "
      ]
     },
     "execution_count": 331,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "table.round(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 332,
   "metadata": {},
   "outputs": [],
   "source": [
    "for v in table.columns:\n",
    "    table.loc['$\\Delta $',v] = table.loc['United States',v] - table.loc['Europe',v] \n",
    "    table.loc['$\\Delta (\\%)$',v] = table.loc['United States',v]/ table.loc['Europe',v] - 1\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 333,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>hypertension</th>\n",
       "      <th>diabetes</th>\n",
       "      <th>lung</th>\n",
       "      <th>heart</th>\n",
       "      <th>stroke</th>\n",
       "      <th>total cond.</th>\n",
       "      <th>ADLs</th>\n",
       "      <th>Life exp (50)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Germany</th>\n",
       "      <td>0.338</td>\n",
       "      <td>0.105</td>\n",
       "      <td>0.042</td>\n",
       "      <td>0.090</td>\n",
       "      <td>0.034</td>\n",
       "      <td>0.610</td>\n",
       "      <td>0.067</td>\n",
       "      <td>31.140</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sweden</th>\n",
       "      <td>0.261</td>\n",
       "      <td>0.079</td>\n",
       "      <td>0.025</td>\n",
       "      <td>0.109</td>\n",
       "      <td>0.028</td>\n",
       "      <td>0.502</td>\n",
       "      <td>0.054</td>\n",
       "      <td>32.110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Netherlands</th>\n",
       "      <td>0.239</td>\n",
       "      <td>0.074</td>\n",
       "      <td>0.062</td>\n",
       "      <td>0.091</td>\n",
       "      <td>0.035</td>\n",
       "      <td>0.501</td>\n",
       "      <td>0.052</td>\n",
       "      <td>31.220</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Spain</th>\n",
       "      <td>0.289</td>\n",
       "      <td>0.125</td>\n",
       "      <td>0.045</td>\n",
       "      <td>0.077</td>\n",
       "      <td>0.018</td>\n",
       "      <td>0.554</td>\n",
       "      <td>0.069</td>\n",
       "      <td>32.260</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Italy</th>\n",
       "      <td>0.350</td>\n",
       "      <td>0.107</td>\n",
       "      <td>0.060</td>\n",
       "      <td>0.082</td>\n",
       "      <td>0.021</td>\n",
       "      <td>0.619</td>\n",
       "      <td>0.075</td>\n",
       "      <td>32.660</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>France</th>\n",
       "      <td>0.256</td>\n",
       "      <td>0.086</td>\n",
       "      <td>0.048</td>\n",
       "      <td>0.103</td>\n",
       "      <td>0.023</td>\n",
       "      <td>0.516</td>\n",
       "      <td>0.072</td>\n",
       "      <td>32.560</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Denmark</th>\n",
       "      <td>0.277</td>\n",
       "      <td>0.066</td>\n",
       "      <td>0.059</td>\n",
       "      <td>0.063</td>\n",
       "      <td>0.038</td>\n",
       "      <td>0.504</td>\n",
       "      <td>0.069</td>\n",
       "      <td>30.150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Europe</th>\n",
       "      <td>0.310</td>\n",
       "      <td>0.102</td>\n",
       "      <td>0.049</td>\n",
       "      <td>0.090</td>\n",
       "      <td>0.027</td>\n",
       "      <td>0.573</td>\n",
       "      <td>0.069</td>\n",
       "      <td>31.959</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>United States</th>\n",
       "      <td>0.445</td>\n",
       "      <td>0.147</td>\n",
       "      <td>0.069</td>\n",
       "      <td>0.159</td>\n",
       "      <td>0.045</td>\n",
       "      <td>0.865</td>\n",
       "      <td>0.108</td>\n",
       "      <td>30.650</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>$\\Delta $</th>\n",
       "      <td>0.136</td>\n",
       "      <td>0.045</td>\n",
       "      <td>0.020</td>\n",
       "      <td>0.069</td>\n",
       "      <td>0.018</td>\n",
       "      <td>0.293</td>\n",
       "      <td>0.039</td>\n",
       "      <td>-1.309</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>$\\Delta (\\%)$</th>\n",
       "      <td>0.439</td>\n",
       "      <td>0.446</td>\n",
       "      <td>0.401</td>\n",
       "      <td>0.765</td>\n",
       "      <td>0.689</td>\n",
       "      <td>0.511</td>\n",
       "      <td>0.570</td>\n",
       "      <td>-0.041</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               hypertension  diabetes   lung  heart  stroke  total cond.  \\\n",
       "Germany               0.338     0.105  0.042  0.090   0.034        0.610   \n",
       "Sweden                0.261     0.079  0.025  0.109   0.028        0.502   \n",
       "Netherlands           0.239     0.074  0.062  0.091   0.035        0.501   \n",
       "Spain                 0.289     0.125  0.045  0.077   0.018        0.554   \n",
       "Italy                 0.350     0.107  0.060  0.082   0.021        0.619   \n",
       "France                0.256     0.086  0.048  0.103   0.023        0.516   \n",
       "Denmark               0.277     0.066  0.059  0.063   0.038        0.504   \n",
       "Europe                0.310     0.102  0.049  0.090   0.027        0.573   \n",
       "United States         0.445     0.147  0.069  0.159   0.045        0.865   \n",
       "$\\Delta $             0.136     0.045  0.020  0.069   0.018        0.293   \n",
       "$\\Delta (\\%)$         0.439     0.446  0.401  0.765   0.689        0.511   \n",
       "\n",
       "                ADLs  Life exp (50)  \n",
       "Germany        0.067         31.140  \n",
       "Sweden         0.054         32.110  \n",
       "Netherlands    0.052         31.220  \n",
       "Spain          0.069         32.260  \n",
       "Italy          0.075         32.660  \n",
       "France         0.072         32.560  \n",
       "Denmark        0.069         30.150  \n",
       "Europe         0.069         31.959  \n",
       "United States  0.108         30.650  \n",
       "$\\Delta $      0.039         -1.309  \n",
       "$\\Delta (\\%)$  0.570         -0.041  "
      ]
     },
     "execution_count": 333,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "table.round(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Output to LaTeX"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 334,
   "metadata": {},
   "outputs": [],
   "source": [
    "table.round(3).to_latex('../tables/table_4_comparison_health.tex')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Additional Material for Table 4 and Static Model (Not Used)\n",
    "\n",
    "This is data on the heath-income gradient for various conditions. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 335,
   "metadata": {},
   "outputs": [],
   "source": [
    "def wmean(x,var,wvar):\n",
    "    xx = x.loc[~x[var].isna(),:]\n",
    "    names = {var: (xx[var] * xx[wvar]).sum()/xx[wvar].sum()}\n",
    "    return pd.Series(names, index=[var])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 336,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "<ipython-input-336-1a370c85c511>:8: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  df_c['hitot_w2'] = df_c['hitot_w2'].clip(lower=p01,upper=p99)\n",
      "/Users/loulou/.local/lib/python3.8/site-packages/pandas/core/indexing.py:1667: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  self.obj[key] = value\n"
     ]
    }
   ],
   "source": [
    "outcomes = ['rhibpe_w1','rdiabe_w1','rlunge_w1','rhearte_w1','rstroke_w1','radla_w1','hitot_w2']\n",
    "table = pd.DataFrame(index=[0,1],columns=outcomes)\n",
    "incs = pd.DataFrame(index=[0,1],columns=['q1','q2','q3','q4'])\n",
    "for c in [0,1]:\n",
    "\tdf_c = df.loc[df['share']==c,:]\n",
    "\tp99 = df_c['hitot_w2'].quantile(0.99)\n",
    "\tp01 = df_c['hitot_w2'].quantile(0.01)\n",
    "\tdf_c['hitot_w2'] = df_c['hitot_w2'].clip(lower=p01,upper=p99)\n",
    "\tdf_c.loc[:,'qinc'] = pd.qcut(df_c.loc[:,'hitot_w2'],q=4)\n",
    "\tfor v in outcomes:\n",
    "\t\tgrad = df_c.groupby('qinc').apply(wmean,var=v,wvar='wgid_w1')\t\n",
    "\t\tgrad.index = [x for x in range(1,5)]\n",
    "\t\tif v!='hitot_w2':\n",
    "\t\t\ttable.loc[c,v] = (1-grad.loc[4,v])/(1-grad.loc[1,v])\n",
    "\t\telse :\n",
    "\t\t\tminc = grad.loc[:,v].mean()\n",
    "\t\t\tgrad.loc[:,v] = grad.loc[:,v]/minc\n",
    "\t\t\ttable.loc[c,v] = grad.loc[4,v]/grad.loc[1,v]\n",
    "\t\t\tincs.loc[c,'q1'] = grad.loc[1,v]\n",
    "\t\t\tincs.loc[c,'q2'] = grad.loc[2,v]\n",
    "\t\t\tincs.loc[c,'q3'] = grad.loc[3,v]\n",
    "\t\t\tincs.loc[c,'q4'] = grad.loc[4,v]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 337,
   "metadata": {},
   "outputs": [],
   "source": [
    "table.index = ['US','EU']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 338,
   "metadata": {},
   "outputs": [],
   "source": [
    "table = table.loc[['EU','US'],['rhibpe_w1','rdiabe_w1','rlunge_w1','rhearte_w1','rstroke_w1','radla_w1']]\n",
    "table.columns = ['Hypertension','Diabetes','Lung Disease','Heart Disease','Stroke','ADL']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This could be added to Table 4. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 339,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Hypertension</th>\n",
       "      <th>Diabetes</th>\n",
       "      <th>Lung Disease</th>\n",
       "      <th>Heart Disease</th>\n",
       "      <th>Stroke</th>\n",
       "      <th>ADL</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>EU</th>\n",
       "      <td>1.166</td>\n",
       "      <td>1.094</td>\n",
       "      <td>1.041</td>\n",
       "      <td>1.032</td>\n",
       "      <td>1.018</td>\n",
       "      <td>1.061</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>US</th>\n",
       "      <td>1.435</td>\n",
       "      <td>1.163</td>\n",
       "      <td>1.114</td>\n",
       "      <td>1.129</td>\n",
       "      <td>1.065</td>\n",
       "      <td>1.276</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    Hypertension  Diabetes  Lung Disease  Heart Disease  Stroke    ADL\n",
       "EU         1.166     1.094         1.041          1.032   1.018  1.061\n",
       "US         1.435     1.163         1.114          1.129   1.065  1.276"
      ]
     },
     "execution_count": 339,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "for c in table.columns:\n",
    "\ttable[c] = table[c].astype('float64')\n",
    "table.round(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 340,
   "metadata": {},
   "outputs": [],
   "source": [
    "table.round(3).to_latex('../tables/table_4_gradient.tex')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For the static models, normalized average income levels within quartiles are needed. Here is the table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 341,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>q1</th>\n",
       "      <th>q2</th>\n",
       "      <th>q3</th>\n",
       "      <th>q4</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>EU</th>\n",
       "      <td>0.290</td>\n",
       "      <td>0.632</td>\n",
       "      <td>0.992</td>\n",
       "      <td>2.086</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>US</th>\n",
       "      <td>0.209</td>\n",
       "      <td>0.521</td>\n",
       "      <td>0.930</td>\n",
       "      <td>2.339</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       q1     q2     q3     q4\n",
       "EU  0.290  0.632  0.992  2.086\n",
       "US  0.209  0.521  0.930  2.339"
      ]
     },
     "execution_count": 341,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "for c in incs.columns:\n",
    "\tincs[c] = incs[c].astype('float64')\n",
    "incs.index = ['US','EU']\n",
    "incs.loc[['EU','US'],:].round(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 342,
   "metadata": {},
   "outputs": [],
   "source": [
    "incs.loc[['EU','US'],:].round(3).to_latex('../tables/table_4_income.tex')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "cf2a50979671a58939829e6829efb726aa5da11149213b77bd50351f899d04fb"
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
